<template>
  <el-dialog
    title="预览文章"
    :visible="articlesShow"
    width="65%"
    @close="cancelBtn"
    >
    <!-- 文章标题 -->
    <h2 class="article-title">{{ articleDetail.title }}</h2>
    <div>
      <span style="margin-right: 15px">{{articleDetail.createTime | parseTimeByString}}</span>
      <span style="margin-right: 15px">{{currentUsername}}</span>
      <span class="el-icon-view"> {{articleDetail.visits}}</span>
    </div>
    <div class="article-content" v-html="articleDetail.articleBody"></div>
  </el-dialog>
</template>

<script>
import { detail } from '@/api/hmmm/articles'
export default {
  data () {
    return {
      articleDetail: {
        title: null,
        articleBody: null,
        createTime: '',
        visits: null
      }
    }
  },
  props: {
    articlesShow: Boolean,
    currentUsername: [String, Number]
  },
  methods: {
    cancelBtn () {
      this.articleDetail = {
        title: null,
        articleBody: null,
        createTime: '',
        visits: null
      }
      this.$emit('update:articlesShow', false)
    },
    async getArticle (id) {
      const { data } = await detail({ id })
      this.articleDetail = data
    }
  }
}
</script>

<style scoped lang='less'>
.article-content{
  margin-top: 15px;
  background: #f5f5f5;
  padding: 10px;
}
</style>
